package com.runa.protocol.analysis;

import com.runa.protocol.dto.IInterData;
import com.runa.protocol.dto.IResponseData;
import com.runa.protocol.dto.ModbusResponseData;
import com.runa.protocol.enums.ModbusFunctionCode;
import com.runa.protocol.enums.ModbusType;

/**
 * @author zhuj
 */
public abstract class MetaBufferAnalysis<T> implements DataAnalysis<T>{

    protected byte[] buffer;

    protected IResponseData responseData;

    @Override
    public IInterData gain() {
        return responseData;
    }

    void createModbusResponse(int slaveId, ModbusFunctionCode functionCode, int length) {
        responseData = new ModbusResponseData(ModbusType.MODBUS_RTU, slaveId, functionCode, length, buffer);
    }

    void createModbusResponse(int slaveId, short transSign, ModbusFunctionCode functionCode, int length) {
        responseData = new ModbusResponseData(ModbusType.MODBUS_TCP, slaveId, functionCode, length, buffer);
        ((ModbusResponseData) responseData).setTransSign(transSign);
    }
}
